﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Nissen_Common
{
	public class DataGridViewCheckBoxHeaderCellHelper
	{
		private DataGridViewCheckBoxColumn _column;
		public DataGridViewCheckBoxHeaderCellHelper(DataGridViewCheckBoxColumn column)
		{
			_column = column;
		}

		public void AddChekBoxHeaderForGridViewColumn()
		{
			DataGridViewCheckBoxHeaderCell newCheckboxHeaderCell = new DataGridViewCheckBoxHeaderCell();
			_column.HeaderCell = newCheckboxHeaderCell;
			_column.HeaderText = null;
			newCheckboxHeaderCell.OnCheckBoxClicked += new CheckBoxClickedHandler(newCheckboxHeaderCell_OnCheckBoxClicked);
		}

		void newCheckboxHeaderCell_OnCheckBoxClicked(bool state)
		{
			for (int i = 0; i < this._column.DataGridView.Rows.Count; i++)
			{
				if (true)
				{
					_column.DataGridView.EndEdit();
				}
				DataGridViewCheckBoxCell cell = _column.DataGridView[_column.Name, i] as DataGridViewCheckBoxCell;
				if (cell != null)
				{
					cell.Value = state;
				}
			}
		}
	}
}
